package com.anrongtec.zcpt.ui.activity.myfocus;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.PopupWindow;

import com.anrongtec.zcpt.R;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by wangyingying on 2017/2/15.
 * 在主页中已加入可以删掉。
 */

public class BackgroundDarkPopupWindow extends PopupWindow {

    @BindView(R.id.et_focus_add)
   public EditText etFocusAdd;
    @BindView(R.id.id_flowlayout)
    TagFlowLayout idFlowlayout;
    private View mMenuView;


    private View.OnTouchListener touchListener;//点击加号回调
    private TagFlowLayout.OnTagClickListener flowLayoutListener;//标签流回调

    public void setTouchListener(View.OnTouchListener touchListener) {
        this.touchListener = touchListener;
    }

    public void onTagClickListener(TagFlowLayout.OnTagClickListener flowLayoutListener,ArrayList<String> list){
        this.flowLayoutListener=flowLayoutListener;

    }




    public BackgroundDarkPopupWindow(Activity context, View.OnClickListener itemsOnClick, ArrayList<String> list) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.popup_focus_add, null);

        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(android.R.style.Animation_Dialog);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                int height = mMenuView.findViewById(R.id.pop_layout).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });

        etFocusAdd.setOnTouchListener(touchListener);
        idFlowlayout.setOnTagClickListener(flowLayoutListener);
    }

}